package com.huawang.mdesign.model.service.controller;

import com.huawang.business.constants.ParamErrorConstants;
import com.huawang.business.dto.*;
import com.huawang.business.dto.diagram.CustomizeColumnDTO;
import com.huawang.business.dto.property.AddModelItem;
import com.huawang.business.dto.property.ItemInfo;
import com.huawang.business.dto.relation.RelationCriterionDTO;
import com.huawang.business.util.ValidateDataUtil;
import com.huawang.business.vo.*;
import com.huawang.mdesign.model.service.config.validation.ValidGroup;
import com.huawang.mdesign.model.service.dto.*;
import com.huawang.mdesign.model.service.vo.*;
import com.huawang.mdesign.model.service.dto.property.MeasurementDTO;
import com.huawang.mdesign.model.service.request.property.SlotDTO;
import com.huawang.mdesign.model.service.inter.MeasurementService;
import com.huawang.mdesign.model.service.inter.ModelService;
import com.huawang.mdesign.model.service.inter.PropertyService;
import com.huawang.mdesign.model.service.inter.RelatedPropertyService;
import com.huawang.mdesign.model.service.inter.override.UAFPropertyManager;
import com.huawang.mdesign.model.service.vo.errorinfo.ModelErrorInfoVo;
import com.huawang.mdesign.model.service.vo.errorinfo.tips.SyncFailTip;
import com.huawang.mdesign.model.service.vo.selectelementitem.SelectElementItem;
import com.huawang.mdesign.model.service.vo.selectelementitem.SelectStereotypeItem;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Tag(name = "模型属性操作")
@RestController
@RequestMapping("/model/property")
public class PropertyController {

    private final UAFPropertyManager propertyManager;

    @Autowired
    private PropertyService propertyService;

    @Autowired
    private ModelService modelService;

    @Autowired
    private MeasurementService measurementService;

    @Autowired
    private RelatedPropertyService relatedPropertyService;

    public PropertyController(UAFPropertyManager propertyManager) {
        this.propertyManager = propertyManager;
    }

    @Operation(summary = "更新属性")
    @PostMapping("/updateValue")
    public BaseResponse<ModelResultVo> updateValue(@Valid @RequestBody ModifyPropertyDTO modifyPropertyDto) {
        ModelResultVo result = propertyManager.updateValue(modifyPropertyDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新属性")
    @PostMapping("/batchUpdateValue")
    public BaseResponse<ModelResultVo> batchUpdateValue(@Valid @RequestBody List<ModifyPropertyDTO> modifyPropertyDtos) {
        ModelResultVo result = propertyManager.batchUpdateValue(modifyPropertyDtos);
        return BaseResponse.success(result);
    }

    @Operation(summary = "更新表格单元格属性")
    @PostMapping("/table/cell/update")
    public BaseResponse<ModelResultVo> updateTableCell(@Validated @RequestBody ModifyTableCellDto model) {
        ValidateDataUtil.isNotEmpty(model.getInstanceId());
        ValidateDataUtil.isNotNull(model.getValue());
        return BaseResponse.success(propertyManager.updateTableCell(model));
    }

    @Operation(summary = "批量更新属性")
    @PostMapping("/updateValueBatch")
    public BaseResponse<ModelResultVo> updateValueBatch(@Valid @RequestBody ModifyPropertyBatchDTO modifyPropertyBatchDTO) {
        ModelResultVo result = propertyManager.updateValueBatch(modifyPropertyBatchDTO);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新需求编号")
    @PostMapping("/multi/update/requirement")
    public BaseResponse<ModelResultVo> multiUpdateRequirement(@Valid @RequestBody MultiUpdateRequirementDTO updateRequirementDTO) {
        ModelResultVo resultVo = propertyManager.multiUpdateRequirements(updateRequirementDTO);
        return BaseResponse.success(resultVo);
    }

    @Operation(summary = "递归修改序号")
    @PostMapping("/recursion/update/requirementId")
    public BaseResponse<ModelResultVo> recursionUpdateSerialNo(@Valid @RequestBody RecursionUpdateSerialNoDTO serialNoDTO) {
        return BaseResponse.success(propertyManager.recursionUpdateSerialNo(serialNoDTO));
    }

    @Operation(summary = "增加属性,并新增模型")
    @PostMapping("/addValue")
    public BaseResponse<ModelResultVo> addValue(@Valid @RequestBody AddPropertyDTO addPropertyDto) {
        ModelResultVo result = propertyManager.addValue(addPropertyDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新模型属性使用:增加属性,并新增模型")
    @PostMapping("/addValueBatch")
    public BaseResponse<ModelResultVo> addValueBatch(@Valid @RequestBody AddPropertyBatchDTO addPropertyDto) {
        ModelResultVo result = propertyManager.addValueBatch(addPropertyDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "追加属性，不新增模型")
    @PostMapping("/appendValue")
    public BaseResponse<ModelResultVo> appendValue(@Valid @RequestBody AppendModelDTO appendModelDto) {
        ModelResultVo result = propertyManager.appendValue(appendModelDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新模型属性使用:追加属性，不新增模型")
    @PostMapping("/appendValueBatch")
    public BaseResponse<ModelResultVo> appendValueBatch(@Valid @RequestBody AppendModelBatchDTO appendModelBatchDTO) {
        ModelResultVo result = propertyManager.appendValueBatch(appendModelBatchDTO);
        return BaseResponse.success(result);
    }

    /**
     * 只能用作operations.commonAppendProperty，其余特殊更新不要用这个函数
     *
     * @param appendModelDtos
     * @return
     */
    @Operation(summary = "批量追加属性，不新增模型")
    @PostMapping("/appendValues")
    public BaseResponse<ModelResultVo> appendValues(@Valid @RequestBody List<AppendModelDTO> appendModelDtos) {
        ModelResultVo result = propertyManager.appendValues(appendModelDtos);
        return BaseResponse.success(result);
    }

    @Operation(summary = "属性值排序")
    @PostMapping("/sort")
    public BaseResponse<ModelResultVo> sortValue(@Valid @RequestBody SortModelDTO sortModelDto) {
        ModelResultVo result = propertyService.sortValue(sortModelDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "删除属性，并删除属性值对应的模型")
    @PostMapping("/deleteValue")
    public BaseResponse<ModelResultVo> deleteValue(@Valid @RequestBody DeletePropertyDTO deletePropertyDto) {
        DeleteModelDTO dto = new DeleteModelDTO();
        dto.setProjectId(deletePropertyDto.getProjectId());
        dto.setIds(Stream.of(deletePropertyDto.getDeleteInstanceId()).collect(Collectors.toList()));
        ModelResultVo result = modelService.deleteByIds(dto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新模型属性使用:删除属性，并删除属性值对应的模型")
    @PostMapping("/deleteValueBatch")
    public BaseResponse<ModelResultVo> deleteValueBatch(@Valid @RequestBody DeletePropertyBatchDTO deletePropertyBatchDTO) {
        DeleteModelDTO dto = new DeleteModelDTO();
        dto.setProjectId(deletePropertyBatchDTO.getProjectId());
        dto.setIds(Stream.of(deletePropertyBatchDTO.getDeleteInstanceId()).collect(Collectors.toList()));
        ModelResultVo result = modelService.deleteByIds(dto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "移除属性，不删除属性值对应的模型")
    @PostMapping("/removeValue")
    public BaseResponse<ModelResultVo> removeValue(@Valid @RequestBody DeletePropertyDTO deletePropertyDto) {
        ModelResultVo result = propertyManager.removeValue(deletePropertyDto);
        return BaseResponse.success(result);
    }

    @Operation(summary = "批量更新模型属性使用:移除属性，不删除属性值对应的模型")
    @PostMapping("/removeValueBatch")
    public BaseResponse<ModelResultVo> removeValueBatch(@Valid @RequestBody DeletePropertyBatchDTO deletePropertyBatchDTO) {
        ModelResultVo result = propertyManager.removeValueBatch(deletePropertyBatchDTO);
        return BaseResponse.success(result);
    }

    // 属性选择弹窗接口更改

    /**
     * @deprecated (数据结构发生变化 ， 暂时不用)
     */
    @Deprecated
    @Operation(summary = "根据模型获取属性可选模型树")
    @PostMapping("/querySelectElementTree")
    public BaseResponse<SelectElementNode> querySelectElementTree(@Valid @RequestBody BuildSelectElementTreeDTO buildSelectElementTreeDto) {
        ValidateDataUtil.isNotEmpty(buildSelectElementTreeDto.getProjectId());
        return BaseResponse.success(propertyService.buildSelectElementTree(buildSelectElementTreeDto));
    }

    @Operation(summary = "根据模型获取属性可选模型列表,分页")
    @PostMapping("/querySelectElementsWithPage")
    public BaseResponse<PageResponseVo> querySelectElementsWithPage(@Valid @RequestBody BuildSelectElementTreeDTO buildSelectElementTreeDto) {
        return BaseResponse.success(propertyService.buildSelectElementsTreeWithPage(buildSelectElementTreeDto));
    }

    @Operation(summary = "关键词搜索,分页")
    @PostMapping("/queryElementByKeywordWithPage")
    public BaseResponse<PageResponseVo> queryElementByKeywordWithPage(@Valid @RequestBody BuildSelectElementTreeDTO buildSelectElementTreeDto) {
        return BaseResponse.success(propertyService.queryElementByKeywordWithPage(buildSelectElementTreeDto));
    }

    @Operation(summary = "批量更新模型属性使用: 关键词搜索,分页")
    @PostMapping("/queryElementByKeywordWithPageBatch")
    public BaseResponse<PageResponseVo> queryElementByKeywordWithPageBatch(
            @Valid @RequestBody BuildSelectElementTreeBatchDTO buildSelectElementTreeBatchDTO) {
        return BaseResponse.success(propertyService.queryElementByKeywordWithPageBatch(buildSelectElementTreeBatchDTO));
    }


    @Operation(summary = "根据模型获取属性可选下拉列表")
    @PostMapping("/querySelectElementList")
    public BaseResponse<List<SelectElementItem>> querySelectElementList(@Valid @RequestBody BuildSelectElementTreeDTO buildSelectElementTreeDto) {
        return BaseResponse.success(
                propertyService.buildSelectElementList(buildSelectElementTreeDto));
    }

    @Operation(summary = "更新值类型为valueSpecification的属性")
    @PostMapping("/modifyPropertyByValueSpecification")
    public BaseResponse<ModelResultVo> modifyPropertyByValueSpecification(
            @Validated(value = ValidGroup.CreateValueSpecification.TypeId.class)
            @RequestBody ModifyPropertyByValueSpecificationDTO modifyPropertyByValueSpecificationDto) {
        return BaseResponse.success(
                propertyService.updatePropertyByValueSpecification(modifyPropertyByValueSpecificationDto));
    }

    @Operation(summary = "更新slot的值")
    @PostMapping("/modifySlotValue")
    public BaseResponse<ModelResultVo> modifySlotValue(@Valid @RequestBody ModifySlotValueDTO dto) {
        return BaseResponse.success(propertyService.modifySlotValue(dto.getProjectId(), dto.getSlotId(), dto.getValue()));
    }

    @Operation(summary = "查询元类/构造型（图表）")
    @GetMapping("/showElementsAndStereotypes")
    public BaseResponse<RowElementTypeVo> showElementsAndStereotypes(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                     String instanceId) {
        return BaseResponse.success(propertyService.queryElementsAndStereotypes(projectId, instanceId));
    }


    @Operation(summary = "查询图表的构造型")
    @GetMapping("/queryDiagramStereotypes")
    public BaseResponse<RowElementTypeVo> queryDiagramStereotypes(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId) {
        return BaseResponse.success(propertyService.queryDiagramStereotypes(projectId));
    }

    @Operation(summary = "分别查询元素/关系的元类和构造型")
    @GetMapping("/showElementsAndStereotypesByType")
    public BaseResponse<RowElementTypeVo> showElementsAndStereotypesByType(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                           @NotBlank(message = ParamErrorConstants.NO_ISRELATIONSHIP_ID) Boolean isQueryRelation) {
        return BaseResponse.success(propertyService.showElementsAndStereotypesByType(projectId, isQueryRelation));
    }

    @Operation(summary = "查询关联（矩阵、关系图）")
    @GetMapping("/showAssociates")
    public BaseResponse<AssociateTypeVo> showAssociates(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                        @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(propertyService.queryAllRelations(projectId, instanceId));
    }

    @Operation(summary = "查询元类（profile）")
    @GetMapping("/showElements")
    public BaseResponse<ElementTypeVo> showElements(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId) {
        return BaseResponse.success(propertyService.queryElements(projectId));
    }

    @Operation(summary = "元素的属性值是一个约束的修改")
    @PostMapping("/modifyElementPropertyValueIsConstraint")
    public BaseResponse<ModelResultVo> modifyPropertyValueIsConstraint(@Valid @RequestBody ModifyPropertyByValueSpecificationDTO modifyPropertyByValueSpecificationDto) {
        return BaseResponse.success(propertyService.createPropertyValueIsConstraint(modifyPropertyByValueSpecificationDto));
    }

    @Operation(summary = "查询模型可应用的构造型")
    @PostMapping("/queryAppliedStereotypeList")
    public BaseResponse<List<SelectStereotypeItem>> queryAppliedStereotypeList(@Valid @RequestBody BuildSelectElementTreeDTO dto) {
        return BaseResponse.success(propertyService.queryAppliedStereotypeList(dto));
    }

    @Operation(summary = "查询多个模型可应用的构造型")
    @PostMapping("/queryMultiAppliedStereotypeList")
    public BaseResponse<List<SelectStereotypeItem>> queryMultiAppliedStereotypeList(@Valid @RequestBody QueryMultiAppliedStereotypeDTO dto) {
        return BaseResponse.success(propertyService.queryMultiAppliedStereotypeList(dto));
    }

    @Operation(summary = "根据指定类型查询可应用的构造型")
    @GetMapping("/queryAppliedStereotypeListByType")
    public BaseResponse<List<String>> queryAppliedStereotypeListByType(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                       @NotBlank(message = ParamErrorConstants.NO_TYPE_ID) String typeId) {
        return BaseResponse.success(propertyService.queryAppliedStereotypeListByType(projectId, typeId));
    }

    @Operation(summary = "获取元素的显示")
    @GetMapping("queryElementDisplay")
    public BaseResponse<List<String>> queryElementDisplay(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                          @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(propertyService.queryElementDisplay(projectId, instanceId));
    }

    @Operation(summary = "批量获取元素的显示")
    @PostMapping("batchQueryElementDisplay")
    public BaseResponse<List<String>> batchQueryElementDisplay(@RequestBody @Valid BatchQueryElementDisplayDTO dto) {
        return BaseResponse.success(propertyService.batchQueryElementDisplay(dto));
    }

    @Operation(summary = "判断元素是否是指定类型")
    @GetMapping("checkElementType")
    public BaseResponse<Boolean> checkElementType(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                  @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId,
                                                  String type) {
        return BaseResponse.success(propertyService.checkElementType(projectId, instanceId, type));
    }

    @Operation(summary = "查询元素的所有元类")
    @PostMapping("/queryElementAllMataClass")
    public BaseResponse<List<String>> queryElementAllMataClass(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                               @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId) {
        return BaseResponse.success(propertyService.queryElementAllMataClass(projectId, instanceId));
    }

    @Operation(summary = "判断模型能否设为该属性的值")
    @PostMapping("/checkValidPropertyValue")
    public BaseResponse<List<CheckValidPropertyValueVo>> checkValidPropertyValue(@Valid @RequestBody CheckValidPropertyValueDTO dto) {
        return BaseResponse.success(propertyService.checkValidPropertyValue(dto));
    }

    @Operation(summary = "批量更新模型使用:查询不同模型相同属性可选模型")
    @PostMapping("/checkValidPropertyValueBatch")
    public BaseResponse<List<CheckValidPropertyValueVo>> checkValidPropertyValueBatch(@Valid @RequestBody CheckValidPropertyValueBatchDTO dto) {
        return BaseResponse.success(propertyService.checkValidPropertyValueBatch(dto));
    }

    @Operation(summary = "查询指定模型的子集属性并返回")
    @PostMapping("/querySubProperties")
    public BaseResponse<SubPropertyTreeVo> querySubProperties(@Valid @RequestBody SubPropertyParamDTO dto) {
        return BaseResponse.success(propertyService.querySubPropertiesByParams(dto));
    }

    @Operation(summary = "查询被约束对象的属性集")
    @PostMapping("/queryConstrainedProps")
    public BaseResponse<ConstraintPropertyNode> queryConstrainedProps(@Valid @RequestBody BuildSelectElementTreeDTO buildSelectElementTreeDto) {
        ValidateDataUtil.isNotEmpty(buildSelectElementTreeDto.getProjectId());
        ValidateDataUtil.isNotEmpty(buildSelectElementTreeDto.getInstanceId());
        return BaseResponse.success(propertyService.queryConstrainedProps(buildSelectElementTreeDto));
    }

    @Operation(summary = "查询关系配置信息")
    @GetMapping("/queryRelationCriterion")
    public BaseResponse<RelationCriterionDTO> queryRelationCriterion(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                     @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId,
                                                                     String type) {
        return BaseResponse.success(propertyService.queryRelationCriterion(projectId, instanceId, type));
    }

    @Operation(summary = "保存表达式配置信息")
    @PostMapping("/new/updateRelationCriterion")
    public BaseResponse<ModelResultVo> newUpdateRelationCriterion(@Valid @RequestBody RelationCriterionDTO dto) {
        return BaseResponse.success(propertyService.newUpdateRelationCriterion(dto));
    }

    @Operation(summary = "查询表达式配置信息")
    @GetMapping("/new/queryRelationCriterion")
    public BaseResponse<CustomizeColumnDTO> newQueryRelationCriterion(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                                      @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId,
                                                                      @RequestParam String type,
                                                                      @RequestParam(required = false) String columnId) {
        return BaseResponse.success(propertyService.newQueryRelationCriterion(projectId, type, instanceId, columnId));
    }

    @Operation(summary = "查询表达式输出类型")
    @GetMapping("/showCriterionTypes")
    public BaseResponse<CriterionTypesVo> showCriterionTypes(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId) {
        return BaseResponse.success(propertyService.showCriterionTypes(projectId));
    }

    @Operation(summary = "校验目标节点能否作为指定类型的父节点")
    @PostMapping("/checkTypeValidOwner")
    public BaseResponse<Boolean> checkTypeValidOwner(@Valid @RequestBody CheckTypeValidOwnerDTO dto) {
        return BaseResponse.success(propertyService.checkTypeValidOwner(dto));
    }

    @Operation(summary = "查询项目中所有属性")
    @GetMapping("/queryAllProperty")
    public BaseResponse<AllPropertyVo> queryAllProperty(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId) {
        return BaseResponse.success(propertyService.queryAllProperty(projectId));
    }

    @Operation(summary = "根据源和目标判断属性应该应用的构造型")
    @GetMapping("/queryPropertyStereotype")
    public BaseResponse<List<String>> queryPropertyStereotype(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                              @NotBlank(message = ParamErrorConstants.NO_SOURCE_INSTANCE_ID) String sourceInstanceId,
                                                              @NotBlank(message = ParamErrorConstants.NO_TARGET_INSTANCE_ID) String targetInstanceId) {
        return BaseResponse.success(propertyService.queryPropertyStereotype(projectId, sourceInstanceId, targetInstanceId));
    }

    @Operation(summary = "查询度量和实际度量")
    @PostMapping("/measurement")
    public BaseResponse<Map<String, List<InstanceVo>>> getMeasurements(@Validated @RequestBody MeasurementDTO measurement) {
        return BaseResponse.success(measurementService.getMeasurements(measurement));
    }

    @Operation(summary = "查询分类器下的所有实例的slot")
    @PostMapping("/measurement/slots")
    public BaseResponse<Map<String, List<SlotDTO>>> getSlotsOfClassifier(@Validated @RequestBody MeasurementDTO measurement) {
        return BaseResponse.success(measurementService.getSlotsOfClassifiers(measurement));
    }

    @Operation(summary = "查询引用该度量集的度量集")
    @GetMapping("/measurement/association")
    public BaseResponse<Set<String>> getAssociatedMeasurementSet(String projectId, String classifier) {
        return BaseResponse.success(measurementService.getAssociatedMeasurementSet(projectId, classifier));
    }

    @Operation(summary = "查询分类器下的所有实例的slot")
    @PostMapping("/measurement/actualMeasurement/slots")
    public BaseResponse<Map<String, List<SlotDTO>>> getSlots(@Validated @RequestBody MeasurementDTO measurement) {
        return BaseResponse.success(measurementService.getSlots(measurement));
    }

    @Operation(summary = "查询属性提示")
    @GetMapping("/queryTip")
    public BaseResponse<PropertyConfigTip> queryTip(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                    @NotBlank(message = ParamErrorConstants.NO_PROPERTY_NAME) String propertyKey) {
        return BaseResponse.success(propertyService.queryTip(propertyKey));
    }

    @Operation(summary = "查询枚举类型属性下拉框列表")
    @GetMapping("/queryItems")
    public BaseResponse<List<ItemInfo>> queryItems(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                   @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId,
                                                   @NotBlank(message = ParamErrorConstants.NO_PROPERTY_KEY) String propertyKey) {
        return BaseResponse.success(propertyService.queryItems(projectId, instanceId, propertyKey));
    }

    @Operation(summary = "查询属性新增模型下拉框列表")
    @GetMapping("/queryAddModelItems")
    public BaseResponse<List<AddModelItem>> queryAddModelItems(@NotBlank(message = ParamErrorConstants.NO_PROJECT_ID) String projectId,
                                                               @NotBlank(message = ParamErrorConstants.NO_INSTANCE_ID) String instanceId,
                                                               @NotBlank(message = ParamErrorConstants.NO_PROPERTY_KEY) String propertyKey
    ) {
        return BaseResponse.success(propertyService.queryAddItems(propertyKey));
    }

    @Operation(summary = "批量更新模型属性使用：查询属性新增模型下拉框列表")
    @PostMapping("/queryMultiAddModelItems")
    public BaseResponse<List<AddModelItem>> queryMultiAddModelItems(@Valid @RequestBody QueryMultiAddModelItemsDTO dto) {
        return BaseResponse.success(propertyService.queryAddItems(dto.getPropertyKey()));
    }

    @Operation(summary = "instance关键词搜索,分页")
    @PostMapping("/fetchInstancesWithKeyword")
    public BaseResponse<PageResponseVo> fetchInstancesWithKeyword(@Valid @RequestBody SelectInstanceByKeywordDTO dto) {
        return BaseResponse.success(propertyService.fetchInstancesWithKeyword(dto));
    }


    @Operation(summary = "判断能否在模型下创建该类型的模型")
    @PostMapping("/checkTypeValidOwnerList")
    public BaseResponse<List<CheckValidPropertyValueVo>> checkTypeValidOwnerList(@Valid @RequestBody CheckTypeValidOwnerDTO dto) {
        return BaseResponse.success(propertyService.checkTypeValidOwnerList(dto));
    }

    @Operation(summary = "保存映射配置项")
    @PostMapping("/savePropertyMapping")
    public BaseResponse<SavePropertyMappingVo> savePropertyMapping(@Valid @RequestBody SavePropertyMappingDTO savePropertyMappingDTO) {
        return BaseResponse.success(propertyService.savePropertyMapping(savePropertyMappingDTO));
    }

    @Operation(summary = "映射配置项同步属性")
    @PostMapping("/syncPropertyMapping")
    public BaseResponse<ModelErrorInfoVo<List<SyncFailTip>>> syncPropertyMapping(@Valid @RequestBody SyncPropertyMappingDTO syncPropertyMappingDTO) {
        return BaseResponse.success(propertyService.syncPropertyMapping(syncPropertyMappingDTO));
    }

    @Operation(summary = "缺失触发器时的事件类型更新属性")
    @PostMapping("/absent/eventType/updateValue")
    public BaseResponse<ModelResultVo> updateValueWithNoTrigger(@Valid @RequestBody AbsentTriggerModifyPropertyDTO modifyPropertyDto) {
        ModelResultVo result = relatedPropertyService.updateValueWithNoTrigger(modifyPropertyDto);
        return BaseResponse.success(result);
    }
}
